<template>
  <div class="edit-panel">
    <div class="edit-tool">
      <div class="item">
        <span @click="backList" class="icon">
          <mu-icon value="返回"></mu-icon>
        </span>
      </div>
      <div class="flex"></div>
      <div class="item" style="text-align:right">
        <span v-show="isShow" @click="backList" class="icon">
          <mu-icon value="完成"></mu-icon>
        </span>
      </div>
    </div>
    <div class="edit-title">{{activeNote.date + '　　'+activeNote.content.length+'字'}}</div>
    <textarea v-focus class="edit-area" v-model="activeNote.content" @keyup="editorNote"></textarea>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "Editor",
  data() {
    return {
      content: "",
      isShow: false
    };
  },
  created() {
    this.content = this.activeNote.content;
  },
  computed: {
    //获取正在操作的便签
    ...mapGetters(["activeNote"])
  },
  directives: {
    focus: {
      inserted(el) {
        el.focus();
      }
    }
  },
  methods: {
    //返回便签列表
    backList() {
      this.$router.push({ path: "/" });
      this.$store.dispatch("backSave", this.activeNote);
    },
    //完成按钮显示&隐藏
    editorNote() {
      if (this.content != this.activeNote.content) {
        this.isShow = true;
      } else {
        this.isShow = false;
      }
    }
  }
};
</script>

<style scoped>
.edit-panel {
  position: relative;
  height: 100%;
   background: #fbfbfb;
}
.edit-tool {
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-align: left;
  display: flex;
  box-align: center;
  -ms-flex-align: center;
  align-items: center;
 
}
.edit-tool .item {
  width: 100px;
  padding: 0 10px;
}
.edit-tool .flex {
  flex: 1;
}
.edit-tool .item .icon {
  font-size: 12px;
  color: #ffca00;
  vertical-align: middle;
  cursor: pointer;
}
.edit-title {
  display: flex;
  height: 30px;
  padding: 0 15px;
  color: #999;
}
.edit-panel .edit-area {
  position: absolute;
  top: 70px;
  bottom: 0;
  padding: 5px 15px;
  width: 100%;
  border: 0;
  resize: none;
  outline: none;
  background: #fbfbfb;
}
</style>